<?php

new set_transcoding();

class set_transcoding extends adminControl
{
	protected function indexAction()
	{
		include_once(D_P . 'data/cache/server.php');

		$sql_state = $url_state = '';
		if(isset($_GET['videostate']))
		{
			$videostate = intval($_GET['videostate']);
			$sql_state = 'AND videostate =' . $videostate;
			$url_state = '&videostate=' . $videostate . '&';
		}
		$pagesize = 25;
		$page = intval($_GET['page']);
		$page < 1 && $page = 1;
		$start = ($page - 1)*$pagesize;


		$rs = $this->db->get_array("SELECT * FROM cms_resource WHERE ifvideo=1 $sql_state ORDER BY rid DESC LIMIT $start, $pagesize");

		$rt = $this->db->get_one("SELECT COUNT(*) AS total FROM cms_resource WHERE ifvideo=1 $sql_state");

		$count = $rt['total'];
		$numofpage = ceil($count/$pagesize);

		$pages = numofpage($count, $page, $numofpage, "$this->basename&" . $url_state);
		$this->fillData('url_state',$url_state);
		$this->fillData('serverdb', $server);
		$this->fillData('count', $count);
		$this->fillData('pages', $pages);
		$this->fillData('videolist', $rs);
		$this->display('set_transcoding');
	}

	protected function getResetAction()
	{
		if (isset($_GET['rid']))
		{
			$rid = intval($_GET['rid']);
			//exit("UPDATE cms_resource SET ifconvert=0,videostate=0,retry=0 WHERE rid=$rid");
			if(isset($_GET['videostate']))
			{
				$url_state = '&videostate=' . intval($_GET['videostate']);
			}
			$this->db->query("UPDATE cms_resource SET ifconvert=0,videostate=0,retry=0 WHERE rid=$rid AND ifvideo=1");
		}
		adminmsg('已经将此视频重新开始了转码', $this->basename . "&page=" . intval($_GET['page']) . $url_state);
	}

	protected function postResetAction()
	{
		if (isset($_POST['rids']))
		{
			$rids = array();
			foreach ($_POST['rids'] as $r)
			{
				$rids[] = intval($r);
			}
			//exit("UPDATE cms_resource SET ifconvert=0,videostate=0,retry=0 WHERE rid IN(" . implode(',', $rids) . ") AND ifvideo=1");
		}
		if (count($rids) > 0)
		{
			if(isset($_GET['videostate']))
			{
				$url_state = '&videostate=' . intval($_GET['videostate']);
			}
			$this->db->query("UPDATE cms_resource SET ifconvert=0,videostate=0,retry=0 WHERE rid IN(" . implode(',', $rids) . ") AND ifvideo=1");
			$count = count($rids);
			adminmsg('已经将' . $count . '个视频内容重新加入了转码队列中', $this->basename . "&page=" . intval($_POST['page']) . $url_state);
		}


	}
}
?>